#include "Event.h"
#include "EventLoop.h"
#include  <unistd.h>

using namespace tmms::network;



Event::Event(/* args */)
{

}

Event::Event(EventLoop *loop,int fd):loop_(loop),fd_(fd)
{

}

Event::Event(EventLoop *loop):loop_(loop)
{

}


Event::~Event()
{
    Close();
}

bool Event::EnableWriting (bool enable)
{
    return loop_->EnableEventWriting(shared_from_this(),enable); //传给参数我自己的this的智能指针
}

bool Event::EnableReading(bool enable)
{
    return loop_->EnableEventReading(shared_from_this(),enable);//传给参数我自己的this的智能指针
}

int Event::Fd() const
{
    return fd_;
}

void Event::Close() 
{
     if(fd_>0)
    {
        ::close(fd_);
        fd_=-1;
    }
}

